<template>
	<view class="index-list animate__animated animate__fadeInLeft animate__fast">
		<view class="index-list1">
			<view>
				<image @tap.stop="openSpace" :src="item.userpic"
				mode="widthFix"
				lazy-load=""></image>
				{{item.username}}
			</view>
			<view v-show="!item.isguanzhu" @tap="guanzhu">
				<view class="icon iconfont icon-zengjia"></view>关注
			</view>
		</view>
		<view class="index-list2" @tap="opendetail">{{item.title}}</view>
		<view class="index-list3 u-f-ajc" @tap="opendetail">
			<!-- 图片 -->
			<image :src="item.titlepic"
			 mode="widthFix"
			 lazy-load=""></image>
			 
			 <!-- 视频 -->
			 <template v-if="item.type == 'video' ">
			 	<view class="icon iconfont icon-bofang index-list-play"></view>
			 	<view class="index-list-playinfo">
			 		{{item.playnum}}次播放 {{item.long}}
			 	</view>
			 </template>
			 
		</view>
		<view class="index-list4 u-f-ac u-f-jsb">
			<view class="u-f-ac">
				<view class="u-f-ac" :class="{'active':(item.infonum.index == 1)}"
				@tap="caozuo('ding')">
					<view class="icon iconfont icon-icon_xiaolian-mian"></view>
					{{item.infonum.dingnum}}
				</view>
				<view :class="{'active':(item.infonum.index == 2)}"
				@tap="caozuo('cai')">
					<view class="icon iconfont icon-kulian"></view>
					{{item.infonum.cainum}}
				</view>
			</view>
			<view>
				<view>
					<view class="icon iconfont icon-pinglun1"></view>
					{{item.commentnum}}
				</view>
				<view>
					<view class="icon iconfont icon-zhuanfa"></view>
					{{item.sharenum}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: Object,
			index: Number
		},
		methods: {
			openSpace(){
				uni.navigateTo({
					url:"../../pages/user-space/user-space?userid="+this.item.userid
				})
			},
			// 关注
			async guanzhu(){
				try{
					let [err,res] = await this.$http.post('/follow',{
						follow_id:this.item.userid
					},{
						token:true,
						checkToken:true,
						checkAuth:true
					});
					// 错误处理
					if (!this.$http.errorCheck(err,res)){
						return;
					}
					// 通知首页修改数据
					uni.showToast({ title: '关注成功' });
					let resdata = {
					 	type:"guanzhu",
					 	userid:this.item.userid,
					 	data:true
					};
					// 通知父组件
					this.$emit('changeevent',resdata);
					// 通知首页
					uni.$emit('updateData',resdata);
				}catch(e){ return; }
			},
			// 顶踩
			async caozuo(type){
				try{
					let index = (type === 'ding') ? 1 : 2; // 操作后的状态
					if(this.item.infonum.index === index) return; // 状态相同不修改
					let [err,res] = await this.$http.post('/support',{
						post_id:this.item.id,
						type:index-1
					},{
						token:true,
						checkToken:true,
						checkAuth:true
					});
					// 错误处理
					if (!this.$http.errorCheck(err,res)) return;
					uni.showToast({
						title: index == 1 ? "顶成功" : "踩成功"
					});
					let resdata = {
						type:"support",
						post_id:this.item.id,
						do:type
					};
					// 通知父组件
					this.$emit('changeevent',resdata);
					// 通知全局
					uni.$emit("updateData",resdata);
				}catch(e){ return; }
			},
			// 进入详情页
			opendetail(){
				uni.navigateTo({
					url: '../../pages/detail/detail?detailData=' + JSON.stringify(this.item)
				});
				this.User.addHistoryList(this.item);
			}
		}
	}
</script>

<style scoped>
	.index-list{
		padding: 20upx;
		border-bottom: 1upx solid #EFEFEF;
	}
	.index-list1{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.index-list1>view:first-child{
		display: flex;
		align-items: center;
		color: #999999;
	}
	.index-list1>view:first-child image{
		width: 80upx;
		height: 80upx;
		border-radius: 100%;
		margin-right: 20upx;
	}
	.index-list1>view:last-child{
		display: flex;
		align-items: center;
	}
	.index-list1>view:last-child{
		background-color: #F4F4F4;
		border-radius: 5px;
		color: #242424;
		padding-left: 16upx;
		padding-right: 16upx;
	}
	.index-list2{
		 padding-top: 15upx;
		 font-size: 32upx;
	}
	.index-list3{
		position: relative;
		padding-top: 15upx;
	}
	.index-list3>image{
		width: 100%;
		border-radius: 20upx;
	}
	.index-list4 view{
		color: #D5D5D5;
	}
	.index-list4{
		padding-top: 15upx;
		padding-bottom: 15upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.index-list4>view:first-child{
		display: flex;
		align-items: center;
	}
	.index-list4>view:last-child{
		display: flex;
		align-items: center;
	}
	.index-list4>view>view{
		display: flex;
		align-items: center;
	}
	.index-list4>view>view>view{
		margin-right: 16upx;
	}
	.index-list4>view>view:first-child{
		margin-right: 16upx;
	}
	.index-list-play{
		position: absolute;
		font-size: 140upx;
		color: #FFFFFF;
	}
	.index-list-playinfo{
		position: absolute;
		background: rgba(51, 51, 51, 0.72);
		color: #FFFFFF;
		bottom: 8upx;
		right: 8upx;
		font-size: 24upx;
		padding: 0 12upx;
		border-radius: 40upx;
	}
	.index-list4 .active, .index-list4 .active>view{
		color: #FFB400;
	}
</style>
